{template common/contentheader}
<script type="text/JavaScript">
$.fn.extend({
	insertAtCaret : function(myValue, needSelect) {
		return this.each(function(i) {
			if (document.selection) {
				// For browsers like Internet Explorer
				this.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
				if (needSelect) {
					sel.moveStart("character", -(myValue.length - 1));
					sel.moveEnd("character", -1);
					sel.select();
				}
			} else if (this.selectionStart || this.selectionStart == '0') {
				// For browsers like Firefox and Webkit based
				var startPos = this.selectionStart;
				var endPos = this.selectionEnd;
				var scrollTop = this.scrollTop;
				this.value = this.value.substring(0, startPos) + myValue
						+ this.value.substring(endPos, this.value.length);
				this.focus();

				if (needSelect) {
					this.selectionStart = startPos + 1;
					this.selectionEnd = startPos + myValue.length - 1;
				} else {
					this.selectionStart = startPos + myValue.length;
					this.selectionEnd = startPos + myValue.length;
				}
				this.scrollTop = scrollTop;
			} else {
				this.value += myValue;
				this.focus();
			}
		});
	}
});
	function isUndefined(variable) {
		return typeof variable == 'undefined' ? true : false;
	}
	function insertunit(text) {
		var credit_formula = $('#credit_formula');
		credit_formula.focus();
		credit_formula.insertAtCaret(text,0);
		formulaexp(credit_formula.val());
	}
	function formulaexp(result) {
		result = result.replace(/ext_credits_1/g, '<u>$setting['ext_credits_1']</u>');
		result = result.replace(/ext_credits_2/g, '<u>$setting['ext_credits_2']</u>');
		result = result.replace(/ext_credits_3/g, '<u>$setting['ext_credits_3']</u>');
		result = result.replace(/total_followers/g, '<u>{lang total_followers:admin}</u>');
		result = result.replace(/total_shares/g, '<u>{lang total_shares:admin}</u>');
		result = result.replace(/total_likes/g, '<u>{lang total_likes:admin}</u>');
		var formulapermexp = $('#formulapermexp');
		formulapermexp.html(result);
	}
	$(document).ready(function($) {
		var credit_formula = $('#credit_formula');
		formulaexp(credit_formula.val());
		});
</script>
<style type="text/css">
.extcredits a {
	margin-right: 5px;
	padding: 2px 5px;
	line-height: 220%;
	border: 1px solid #B6CFD9;
	background: white;
	white-space: nowrap;
}
u {
text-decoration: underline;
color: #090;
}
</style>
<div class="setcontent">
	<div class="settitle">
		<h3>{lang credit_setting:admin}</h3>{template user/creditsetting-nav}
	</div>
	<div class="alert alert-info mt10">
	<span class="label label-info">{lang info:admin}</span>
	{lang tip_credit_formula:admin}
	</div>
	<div class="setform">
		<form class="pzform" action="{url admin/credit?type=setting&act=save}" method="post">
			<div class="formgroup">
				<label class="formlabel">ext_credits_1{lang creditsname:admin}:</label>
				<div class="formcontrol">
					<input type="text" name="ext_credits_1" value="$setting['ext_credits_1']"/>
				</div>
				<span class="formhelp">ext_credits_1 {lang creditsname_tip:admin}</span>
			</div>
			<div class="formgroup">
				<label class="formlabel">ext_credits_2{lang creditsname:admin}:</label>
				<div class="formcontrol">
					<input type="text" name="ext_credits_2" value="$setting['ext_credits_2']"/>
				</div>
				<span class="formhelp">ext_credits_2 {lang creditsname_tip:admin}</span>
			</div>
			<div class="formgroup">
				<label class="formlabel">ext_credits_3 {lang creditsname:admin}:</label>
				<div class="formcontrol">
					<input type="text" name="ext_credits_3" value="$setting['ext_credits_3']"/>
				</div>
				<span class="formhelp">ext_credits_3 {lang creditsname_tip:admin}</span>
			</div>
			<div class="formgroup">
				<label class="formlabel">{lang credit_type:admin}:</label>
				<div class="controls">
					<p class="extcredits">
		              	<a href="javascript:;" onclick="insertunit('total_followers')">{lang total_followers:admin}</a>
		              	<a href="javascript:;" onclick="insertunit('total_shares')">{lang total_shares:admin}</a>
		              	<a href="javascript:;" onclick="insertunit('total_likes')">{lang total_likes:admin}</a>
		              	<a href="javascript:;" onclick="insertunit('ext_credits_1')">$setting['ext_credits_1']</a>
		              	<a href="javascript:;" onclick="insertunit('ext_credits_2')">$setting['ext_credits_2']</a>
		              	<a href="javascript:;" onclick="insertunit('ext_credits_3')">$setting['ext_credits_3']</a>
		              	<a href="javascript:;" onclick="insertunit(' - ')">&nbsp;-&nbsp;</a>
		              	<a href="javascript:;" onclick="insertunit(' + ')">&nbsp;+&nbsp;</a>
		              	<a href="javascript:;" onclick="insertunit(' * ')">&nbsp;*&nbsp;</a> 
		              	<a href="javascript:;" onclick="insertunit(' / ')">&nbsp;/&nbsp;</a>
		              	<a href="javascript:;" onclick="insertunit(' (', ') ')">&nbsp;(&nbsp;)&nbsp;</a>
		              </p>
				</div>
			</div> 
			
		<div class="formgroup">
            <label class="formlabel" for="credit_formula">{lang credit_formula:admin}:</label>
            <div class="controls">
              <p><u>{lang credits:admin}</u>=<span id="formulapermexp"></span></p>
              <textarea class="input-xlarge" id="credit_formula" onkeyup="formulaexp(this.value);" name="credit_formula" rows="3">$setting['credit_formula']</textarea>
              <p class="help-block">{lang tip_credit_formula:admin}</p>
            </div>
          </div>
			
			<div class="formbuttons">
				<button type="submit" class="btn btn-primary">{lang save:admin}</button>
			</div>
		</form>
	</div>
</div>
{template common/contentfooter}